package com.syj.jsxjj.ui.lend.fragment;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.IdRes;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.TextView;

import com.google.gson.Gson;
import com.syj.jsxjj.R;
import com.syj.jsxjj.app.App;
import com.syj.jsxjj.base.BaseFragment;
import com.syj.jsxjj.config.Constant;
import com.syj.jsxjj.events.AuthenticationRefreshEvent;
import com.syj.jsxjj.events.FragmentRefreshEvent;
import com.syj.jsxjj.events.UIBaseEvent;
import com.syj.jsxjj.http.HttpManager;
import com.syj.jsxjj.http.HttpSubscriber;
import com.syj.jsxjj.ui.lend.activity.BankInputPwdActivity;
import com.syj.jsxjj.ui.lend.activity.LendConfirmLoanActivity;
import com.syj.jsxjj.ui.lend.activity.LoanActivity;
import com.syj.jsxjj.ui.lend.adapter.HomeBannerImageAdapter;
import com.syj.jsxjj.ui.lend.bean.ConfirmLoanBean;
import com.syj.jsxjj.ui.lend.bean.HomeBean;
import com.syj.jsxjj.ui.lend.contract.LendContract;
import com.syj.jsxjj.ui.lend.presenter.LendPresenter;
import com.syj.jsxjj.ui.renzheng.bean.AuthenticationBean;
import com.syj.jsxjj.ui.renzheng.bean.ContentBean;
import com.syj.jsxjj.util.SpUtil;
import com.syj.jsxjj.util.ToastUtil;
import com.syj.jsxjj.util.Tool;
import com.syj.jsxjj.widget.HomeSeekBar;
import com.syj.jsxjj.widget.LockableScrollView;
import com.syj.jsxjj.widget.ViewPagerIndicator;
import com.syj.jsxjj.widget.loading.LoadingLayout;
import com.tendcloud.tenddata.TCAgent;
import com.umeng.analytics.MobclickAgent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


/**********
 * 借款
 */
public class LendFragment extends BaseFragment<LendPresenter> implements OnClickListener, LendContract.View {
    @BindView(R.id.ll_lend)
    LinearLayout mLlLend;
    @BindView(R.id.loading_layout)
    LoadingLayout mLoadingLayout;
    @BindView(R.id.scroll_view)
    LockableScrollView mScrollView; //滚动view
    @BindView(R.id.refresh)
    SwipeRefreshLayout mRefresh;    //刷新view
    @BindView(R.id.ll_loan_content)
    LinearLayout mLlLoanContent;   //未借款时布局
    @BindView(R.id.rg_limit)
    RadioGroup mRgDays; //借款日期容器
    @BindView(R.id.rb_seven_day)
    RadioButton mRbSevenDay;
    @BindView(R.id.rb_fourteen_day)
    RadioButton mRbFourTeen;
    @BindView(R.id.tv_rent_btn)
    TextView mTvRentBtn;        //登录or借款按钮
    @BindView(R.id.ll_status_content)
    FrameLayout mLlStatusContent;  //借款后布局

    @BindView(R.id.ll_surplus_status)
    LinearLayout mLlSurplusStatus;

    @BindView(R.id.viewPager)
    ViewPager mViewPage;
    @BindView(R.id.vpIndicator)
    ViewPagerIndicator mPagerIndicator;
    @BindView(R.id.ll_MoneyAndDay)
    LinearLayout mMoneyDayLayout;
    @BindView(R.id.tv_loanMoney)
    TextView mLoanMoneyText;
    @BindView(R.id.sb_money)
    HomeSeekBar mMoneySeekBar;
    @BindView(R.id.tv_loan_fee)
    TextView tvLoanFee;
    @BindView(R.id.tv_select_money)
    TextView tvSelectMoney;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.fl_product_list)
    FrameLayout flProductList;
    public static LendFragment lendFragment;
    private String loanMoney;
    private int loanDay;
    private String loanFee;
    private HomeBean.AmountDaysListBean moneyPeriodBean;
    private List<HomeBean.BannerListBean> mActivityListBean = new ArrayList<>();
    private ImageHandler playHandler = new ImageHandler(new WeakReference<>(this));
    private HomeBannerImageAdapter homeBannerImageAdapter;
    private ContentBean contentBean;

    public static LendFragment getInstance() {
        if (lendFragment == null) {
            lendFragment = new LendFragment();
        }
        return lendFragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_lend_main;
    }

    @Override
    public void initPresenter() {
        mPresenter.init(this);
    }

    @Override
    public void loadData() {
        EventBus.getDefault().register(this);
        initView();
    }

    private void initView() {
        mTitle.setTitle(false, "借款");
        mRefresh.setColorSchemeColors(ContextCompat.getColor(mContext, R.color.theme_color));
        //加载数据
        mLoadingLayout.setStatus(LoadingLayout.Loading);
        mPresenter.loadIndex();
        mRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mPresenter.loadIndex();
            }
        });
        mRgDays.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                if (checkedId == mRbSevenDay.getId()) {
                    loanDay = 7;
                } else {
                    loanDay = 14;
                }
                calculateRate(moneyPeriodBean);
            }
        });
        mRgDays.check(mRbFourTeen.getId());
    }

    private int realMaxMoney;
    private HomeBean result;

    @Override
    public void indexSuccess(HomeBean result) {
        mLoadingLayout.setStatus(LoadingLayout.Success);
        HomeBean.AmountDaysListBean amount_days_list = new HomeBean.AmountDaysListBean();

        List<String> amounts = new ArrayList<>();
        amounts.add("1000");
        amounts.add("2000");
        amounts.add("5000");
        amounts.add("10000");
        amounts.add("10000+");
        amount_days_list.setAmounts(amounts);

        List<Integer> days = new ArrayList<>();
        days.add(7);
        days.add(14);
        amount_days_list.setDays(days);

        List<Integer> interests = new ArrayList<>();
        interests.add(50000);
        interests.add(100000);
        amount_days_list.setInterests(interests);
        if (result == null) {
            return;
        }
        this.result = result;
        result.setAmount_days_list(amount_days_list);
        App.arrayList = (ArrayList<HomeBean.PlateList2Bean>) result.getPlateList2();
        //获取最大的天数
        loanDay = days.get(days.size() - 1);

        //金额集合
        moneyPeriodBean = result.getAmount_days_list();
        List<HomeBean.BannerListBean> img = new ArrayList<>();
        HomeBean.BannerListBean item1 = new HomeBean.BannerListBean();
        item1.setImgUrlRes(R.mipmap.banner1_img);
        item1.setLinkImg(R.mipmap.banner1_url);
        img.add(item1);
        HomeBean.BannerListBean item2 = new HomeBean.BannerListBean();
        item2.setImgUrlRes(R.mipmap.banner2_img);
        item2.setLinkImg(R.mipmap.banner2_url);
        img.add(item2);
        mActivityListBean = img;

        realMaxMoney = 10000;
        loanMoney = amounts.get(0);

        mMoneySeekBar.setMax(amounts.size() - 1);
        mMoneySeekBar.setProgress(0);
        tvSelectMoney.setText(loanMoney + "元");
        calculateRate(moneyPeriodBean);
        initViewPager();
        //获取数据后进行显示在界面上
        setData();
        mHandler.sendEmptyMessage(1);

        setSeekBar();
    }


    private void setSeekBar() {
        mMoneySeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
                if (moneyPeriodBean == null) {
                    return;
                }
                int position = progress;
                loanMoney = moneyPeriodBean.getAmounts().get(position);
                tvSelectMoney.setText(loanMoney + "元");
                //下面到账金额的改变
                calculateRate(moneyPeriodBean);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                //seekBar.setProgress(mMoneySeekBar.getProgress());
            }
        });

    }

    @Override
    public void toLoanSuccess(ConfirmLoanBean result) {
        Intent intent = new Intent(getActivity(), LendConfirmLoanActivity.class);
        intent.putExtra(BankInputPwdActivity.TAG_OPERATE_BEAN, result);
        startActivity(intent);
    }

    @Override
    public void confirmFailedSuccess() {
        mPresenter.loadIndex();
        EventBus.getDefault().post(new FragmentRefreshEvent(UIBaseEvent.EVENT_LOAN_FAILED));
    }

    @Override
    public void showLoading(String content) {
        if (moneyPeriodBean != null) {
            App.loadingContent(mActivity, content);
        }
    }

    @Override
    public void stopLoading() {
        App.hideLoading();
        if (mRefresh.isRefreshing()) {
            mRefresh.setRefreshing(false);
        }
    }

    /**
     * @param msg  请求异常信息
     * @param type 若有多个请求，用于区分不同请求（不同请求失败或有不同的处理）
     */
    @Override
    public void showErrorMsg(String msg, String type) {
        if (TextUtils.isEmpty(type)) {
            return;
        }
        if (type.equals(mPresenter.TYPE_INDEX)) {//首页接口
            ToastUtil.showToast(msg);
            loadingStatusView(msg);
        }
    }

    //为view设置数据
    private void setData() {
        //当前状态，是已借款还是未结款
        //String loanStatus = SpUtil.getString(Constant.CACHE_LOAN_STATUS);
        if (App.getConfig().getLoginStatus()&&App.getConfig().getUserInfo().getLoanStatus() != null && App.getConfig().getUserInfo().getLoanStatus().equals(Constant.CACHE_LOANED)) {//已借款
            //long time = SpUtil.getLong(Constant.CACHE_TIME);
            int countDown = (int) (30 - (System.currentTimeMillis() - App.getConfig().getUserInfo().getLoanTime()) / 1000);//间隔时间，小于30秒显示倒计时页面
            if (countDown > 0) {
                showView(mLlStatusContent);
                Tool.countTime(countDown, new Subscriber<Integer>() {
                    @Override
                    public void onCompleted() {
                        setData();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(Integer integer) {
                        tvTime.setText(integer + "s");
                    }
                });
            } else {
                showView(mLlSurplusStatus);
                getChildFragmentManager().beginTransaction()
                        .replace(R.id.fl_product_list
                                , ProductListFragment.newInstance((ArrayList<HomeBean.PlateList2Bean>) result.getPlateList2())).commit();
            }

        } else {
            showView(mLlLoanContent);
        }
    }

    /**
     * 切换 未借款、借款中。倒计时布局
     *
     * @param view
     */
    private void showView(View view) {
        switch (view.getId()) {
            case R.id.ll_loan_content:
                mLlLoanContent.setVisibility(View.VISIBLE);
                mLlStatusContent.setVisibility(View.GONE);
                mLlSurplusStatus.setVisibility(View.GONE);
                break;
            case R.id.ll_status_content:
                mLlLoanContent.setVisibility(View.GONE);
                mLlStatusContent.setVisibility(View.VISIBLE);
                mLlSurplusStatus.setVisibility(View.GONE);
                break;
            case R.id.ll_surplus_status:
                mLlLoanContent.setVisibility(View.GONE);
                mLlStatusContent.setVisibility(View.GONE);
                mLlSurplusStatus.setVisibility(View.VISIBLE);
                break;
        }
    }


    private void loadingStatusView(String message) {
        if ("网络不可用".equals(message)) {

        } else {
            mLoadingLayout.setErrorText(message)
                    .setStatus(LoadingLayout.Error);
        }
        mLoadingLayout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
            @Override
            public void onReload(View v) {
                mPresenter.loadIndex();
            }
        });
    }


    @OnClick({R.id.tv_rent_btn, R.id.tv_more_product})
    public void onClick(View v) {
        if (Tool.isFastDoubleClick()) {
            return;
        }
        switch (v.getId()) {
            case R.id.tv_rent_btn:  //借款按钮
                MobclickAgent.onEvent(getContext(), "Home_ApplyBorrow");
                TCAgent.onEvent(getContext(), "Home_ApplyBorrow");
                if (!App.getConfig().getLoginStatus()) {
                    App.toLogin(getActivity());
                } else {
                    if (contentBean != null) {
                        if (contentBean.getPersonal() == null) {
                            ToastUtil.showToast("请先填写个人信息");
                        } else if (contentBean.getOperator() == null) {
                            ToastUtil.showToast("请先填写运营商信息");
                        } else if (contentBean.getContract() == null) {
                            ToastUtil.showToast("请先填写联系人信息");
                        }else {
                            ConfirmLoanBean confirmLoanBean = new ConfirmLoanBean();
                            confirmLoanBean.setMoney(loanMoney + "");
                            confirmLoanBean.setPeriod(loanDay + "");
                            if (loanMoney.contains("+")) {
                                confirmLoanBean.setTrue_money((realMaxMoney - Integer.parseInt(loanFee.replace("+", ""))) + "+");
                            } else {
                                confirmLoanBean.setTrue_money((Integer.parseInt(loanMoney) - Integer.parseInt(loanFee)) + "");
                            }
                            confirmLoanBean.setCounter_fee(loanFee + "");
                            confirmLoanBean.setReal_pay_pwd_status(SpUtil.getString(Constant.CACHE_PAY_PASS));
                            Intent intent = new Intent(getActivity(), LendConfirmLoanActivity.class);
                            intent.putExtra(BankInputPwdActivity.TAG_OPERATE_BEAN, confirmLoanBean);
                            startActivity(intent);
                        }

                    } else {
                        ToastUtil.showToast("请重新获取数据");
                    }
                }
                break;
            case R.id.tv_more_product:
                startActivity(LoanActivity.class);
                break;
        }
    }

    /**
     * 当天数选择的时候，计算费用
     */
    private void calculateRate(HomeBean.AmountDaysListBean amountDays) {
        if (amountDays == null) {
            tvLoanFee.setText("0元");
            mLoanMoneyText.setText("0元");
            return;
        }
        List<Integer> days = amountDays.getDays();
        for (int i = 0; i < days.size(); i++) {
            if (loanDay == days.get(i)) {
                if (loanMoney.contains("+")) {
                    loanFee = realMaxMoney * (amountDays.getInterests().get(i) / 100) / realMaxMoney + "+";
                    mLoanMoneyText.setText((realMaxMoney - Integer.parseInt(loanFee.replace("+", ""))) + "+元");
                } else {
                    loanFee = Integer.parseInt(loanMoney) * (amountDays.getInterests().get(i) / 100) / realMaxMoney + "";
                    mLoanMoneyText.setText((Integer.parseInt(loanMoney) - Integer.parseInt(loanFee)) + "元");
                }
                tvLoanFee.setText(loanFee + "元");

                break;
            }
        }
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(FragmentRefreshEvent event) {
        //当借款申请成功、还款或续期成功、登录成、退出功时刷新数据
        if (event.getType() == UIBaseEvent.EVENT_LOAN_SUCCESS ||
                event.getType() == UIBaseEvent.EVENT_LOGIN ||
                event.getType() == UIBaseEvent.EVENT_REPAY_SUCCESS ||
                event.getType() == UIBaseEvent.EVENT_LOGOUT ||
                event.getType() == UIBaseEvent.REFRESHINDEX) {
            // 数据刷新
            mPresenter.loadIndex();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onAuthenticationRefresh(AuthenticationRefreshEvent event) {
        // 认证成功 数据刷新
        mPresenter.loadIndex();
    }

    private void toLoan() {

        mPresenter.toLoan(String.valueOf(loanMoney), String.valueOf(loanDay));
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            mPresenter.loadIndex();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        //mRollView.play();
        MobclickAgent.onPageStart("首页"); //统计页面，"MainScreen"为页面名称，可自定义
        MobclickAgent.onEvent(getContext(), "lend");
        TCAgent.onPageStart(mContext, "首页");
        TCAgent.onEvent(getContext(), "lend");
        getRenZhengData();
    }


    @Override
    public void onPause() {
        super.onPause();
        //mRollView.onStop();
        MobclickAgent.onPageEnd("首页");
        TCAgent.onPageEnd(mContext, "首页");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);
        lendFragment = null;
        if (subscribe != null && !subscribe.isUnsubscribed()) {
            subscribe.unsubscribe();
        }
        /*if (bankCardSubscribe != null && !bankCardSubscribe.isUnsubscribed()) {
            bankCardSubscribe.unsubscribe();
        }*/

    }

    /**
     * viewPager的轮播切换
     */
    private void initViewPager() {
        Log.i("列表", mActivityListBean.size() + mActivityListBean.toString());
        if (!Tool.isBlank(mActivityListBean.size() + "")) {
            homeBannerImageAdapter = new HomeBannerImageAdapter(mActivity, mActivityListBean);
            mViewPage.setAdapter(homeBannerImageAdapter);
            mPagerIndicator.setViewPager(mViewPage, mActivityListBean.size());
            mPagerIndicator.setOnPageScroll(new ViewPager.OnPageChangeListener() {
                // 配合Adapter的currentItem字段进行设置。
                @Override
                public void onPageSelected(int arg0) {
                    playHandler.sendMessage(Message.obtain(playHandler, ImageHandler.MSG_PAGE_CHANGED, arg0, 0));
                }

                @Override
                public void onPageScrolled(int arg0, float arg1, int arg2) {
                }

                // 覆写该方法实现轮播效果的暂停和恢复
                @Override
                public void onPageScrollStateChanged(int arg0) {
                    switch (arg0) {
                        case ViewPager.SCROLL_STATE_DRAGGING:
                            playHandler.sendEmptyMessage(ImageHandler.MSG_KEEP_SILENT);
                            break;
                        case ViewPager.SCROLL_STATE_IDLE:
                            playHandler.sendEmptyMessageDelayed(ImageHandler.MSG_UPDATE_IMAGE, ImageHandler.MSG_DELAY);
                            break;
                        default:
                            break;
                    }
                }
            });
            mViewPage.setCurrentItem(0);
            playHandler.sendEmptyMessageDelayed(ImageHandler.MSG_UPDATE_IMAGE, ImageHandler.MSG_DELAY);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private static class ImageHandler extends Handler {
        /**
         * 请求更新显示的View,即进行轮播
         */
        protected static final int MSG_UPDATE_IMAGE = 1;
        /**
         * 请求暂停轮播。
         */
        protected static final int MSG_KEEP_SILENT = 2;
        /**
         * 请求恢复轮播。
         */
        protected static final int MSG_BREAK_SILENT = 3;
        /**
         * 记录最新的页号，当用户手动滑动时需要记录新页号，否则会使轮播的页面出错。
         * 例如当前如果在第一页，本来准备播放的是第二页，而这时候用户滑动到了末页，
         * 则应该播放的是第一页，如果继续按照原来的第二页播放，则逻辑上有问题。
         */
        protected static final int MSG_PAGE_CHANGED = 4;
        // 轮播间隔时间
        protected static final long MSG_DELAY = 3000;
        // 使用弱引用避免Handler泄露.这里的泛型参数可以不是Activity，也可以是Fragment等
        private WeakReference<LendFragment> weakReference;
        private int currentItem = 0;

        protected ImageHandler(WeakReference<LendFragment> wk) {
            weakReference = wk;
        }

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            LendFragment lendFragment = weakReference.get();
            if (lendFragment == null) {
                // Activity已经回收，无需再处理UI了
                return;
            }
            // 检查消息队列并移除未发送的消息，这主要是避免在复杂环境下消息出现重复等问题。
            if (lendFragment.playHandler.hasMessages(MSG_UPDATE_IMAGE)) {
                lendFragment.playHandler.removeMessages(MSG_UPDATE_IMAGE);
            }
            switch (msg.what) {
                case MSG_UPDATE_IMAGE:
                    currentItem = lendFragment.mViewPage.getCurrentItem();
                    currentItem++;
                    // currentItem = currentItem % activity.PAGE_COUNT;
                    lendFragment.mViewPage.setCurrentItem(currentItem, true);
                    lendFragment.playHandler.sendEmptyMessageDelayed(MSG_UPDATE_IMAGE, MSG_DELAY);
                    break;
                case MSG_KEEP_SILENT:
                    // 只要不发送消息就暂停了
                    break;
                case MSG_BREAK_SILENT:
                    lendFragment.playHandler.sendEmptyMessageDelayed(MSG_UPDATE_IMAGE, MSG_DELAY);
                    break;
                case MSG_PAGE_CHANGED:
                    // 记录当前的页号，避免播放的时候页面显示不正确。
                    currentItem = msg.arg1;
                    break;
                default:
                    break;
            }
        }
    }

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    if (mActivityListBean != null && mActivityListBean.size() != 0) {
                        HomeBannerImageAdapter adapter = (HomeBannerImageAdapter) mViewPage.getAdapter();
                        adapter.updateItem(mActivityListBean, mViewPage);
                        mPagerIndicator.setViewPager(mViewPage, mActivityListBean.size());
                    }
                    break;
                default:
                    break;
            }
            super.handleMessage(msg);
        }
    };


    private Subscription subscribe;
    //private Subscription bankCardSubscribe;

    private void getRenZhengData() {
        if (!App.getConfig().getLoginStatus()){
            return;
        }
        subscribe = HttpManager.getStringApi().queryCertification("1").subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HttpSubscriber<String>() {

                    @Override
                    protected void _onStart() {

                    }

                    @Override
                    protected void _onNext(String s) {
                        s = s.replace("\\", "").replace("\"{", "{").replace("}\"", "}");
                        try {
                            JSONObject response = new JSONObject(s);
                            if (response.getString("code").equals("0")) {
                                AuthenticationBean bean = new Gson().fromJson(response.getString("result"), AuthenticationBean.class);
                                if (contentBean == null) {
                                    contentBean = bean.getContent();
                                } else {
                                    contentBean.setContract(bean.getContent().getContract());
                                    contentBean.setOperator(bean.getContent().getOperator());
                                    contentBean.setPersonal(bean.getContent().getPersonal());
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }

                    @Override
                    protected void _onError(String message) {

                    }

                    @Override
                    protected void _onCompleted() {

                    }
                });
        /*bankCardSubscribe = HttpManager.getStringApi().queryCertification("3").subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HttpSubscriber<String>() {

                    @Override
                    protected void _onStart() {

                    }

                    @Override
                    protected void _onNext(String s) {
                        s = s.replace("\\", "").replace("\"{", "{").replace("}\"", "}");
                        try {
                            JSONObject response = new JSONObject(s);
                            if (response.getString("code").equals("0")) {
                                AuthenticationBean bean = new Gson().fromJson(response.getString("result"), AuthenticationBean.class);
                                if (contentBean == null) {
                                    contentBean = bean.getContent();
                                } else {
                                    contentBean.setBankcard(bean.getContent().getBankcard());
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }

                    @Override
                    protected void _onError(String message) {

                    }

                    @Override
                    protected void _onCompleted() {

                    }
                });*/
    }
}
